package com.qinglei.recoup.system.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库配置类
 */

public class JdbcUtil {
    private static final String DriverClassName = " com.mysql.cj.jdbc.Driver";
    private static final String URL = "jdbc:mysql://rm-2zex01fw001031b0d3o.mysql.rds.aliyuncs.com:3306/qlsleep_dev?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true";
    private static final String USER = "qinglei0606";
    private static final String PASSWORD = "ql_123456";

    static {
        try {
            Class.forName(DriverClassName);//将"com.mysql.jdbc.Driver"类的Class类对象加载到运行时内存中
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    //定义获取Connection对象的方法
    public static Connection getConnection() {
        //定义Connection对象
        Connection conn = null;
        if (conn == null) {
            try {
                conn = DriverManager.getConnection(URL, USER, PASSWORD);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return conn;
    }

    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 	根据id查询数据
     * @param id	要查询的数据的id
     * @throws Exception
     */
    public static void selectById(Integer id) throws Exception {
//        //取得连接对象
//        Connection conn = JdbcUtil.getConnection();
//        //准备sql语句
//        String sql = "SELECT * FROM emp WHERE empno = " + id;
//        //取得预编译对象
//        PreparedStatement pst = conn.prepareStatement(sql);
//        //执行sql语句
//        ResultSet rs = pst.executeQuery();
//        //判断返回值是否存在，并取出返回值
//        if (rs.next()) {
//               }
//        //关闭连接对象
//        JdbcUtil.close(conn);
    }


}
